/**
 * 角色列表
 *
 * @author liuxiaotang
 */
define(["app", "comm/pager/PagerControl", "js/services/MessageBox", "js/services/MuseService"], function (app) {

    var deps = ["$scope", "$state", "$modal", "MessageBox", "MuseService"];

    function controller ($scope, $state, $modal, MessageBox, MuseService) {
        //初始化查询对象 和 分页对象
        app.regsiterCacheData($scope, $state);
        $scope.queryObj = $scope.queryObj || {};

        //获取列表
        $scope.getObjList = function () {
            MuseService.post("admin/adminrole/list.json").success(
                function (data, status, headers, config) {
                    if (data.state == 0) {
                        $scope.adminRoleList = data.data;
                    } else {
                        MessageBox.notify('获取列表失败：' + data.message);
                    }
                });
        };

        $scope.getObjList();

        //新增
        $scope.add = function () {
            $state.go('adminroleEdit');
        };

        //编辑
        $scope.edit = function (id) {
            $state.go('adminroleEdit', {roleId: id});
        };

        //删除
        $scope.delete = function (id) {
            var dialog = MessageBox.confirm("确认要删除该信息吗？");
            dialog.result.then(function () {
                MuseService.post("admin/adminrole/" + id + "/delete.json").success(
                    function (data, status, headers, config) {
                        if (data.state == 0) {
                            MessageBox.notify('删除成功！');
                            $scope.getObjList();
                        } else {
                            MessageBox.notify('获取信息失败：' + data.message);
                        }
                    });
            });

        };
    }

    controller.$inject = deps;
    app.lazy.controller("AdminRoleListController", controller);
});
